package com.wisdom.tools;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;

import com.hisun.phone.core.voice.model.ReceiveVoiceInfo;
import com.bluecall.sipua.R;

public final class CCPUtil {
	/**
	 * 通话时间 格式00:00:00
	 * 
	 * @param duration
	 * @return
	 */
	public static String getCallDurationShow(long duration) {
		if (duration / 60 == 0) {
			String second = "00";

			if (duration < 10) {
				second = "0" + duration;
			} else {
				second = duration + "";
			}
			return "00:" + second;
		} else {
			String minute = "00";
			String second = "00";
			String hour = "00";
			if ((duration / 60) < 10) {
				minute = "0" + (duration / 60);
			} else {
				if ((duration / 60) > 59) {
					if ((duration / 3600) < 10) {
						hour = "0" + (duration / 3600);
					} else {
						hour = (duration / 3600) + "";
					}

					if ((duration / 60) % 60 < 10) {
						minute = "0" + (duration / 60) % 60;
					} else {
						minute = (duration / 60) % 60 + "";
					}

				} else {
					minute = (duration / 60) + "";
				}
			}
			if ((duration % 60) < 10) {
				second = "0" + (duration % 60);
			} else {
				second = (duration % 60) + "";
			}
			if (hour.equals("00")) {
				return minute + ":" + second;
			} else {
				return hour + ":" + minute + ":" + second;
			}
		}
	}
	
	//voice .show notification ..
	public static void showNewVoiceMessageNoti(Context context ,ReceiveVoiceInfo rVoice) throws IOException {
		
		
	}
	
	//voice .show notification ..
	public static void showNewInterPhoneNoti(Context context ,String config) throws IOException {
		
	}
	
	static MediaPlayer mediaPlayer = null;
	public static void playNotifycationMusic (Context context ,String voicePath) throws IOException  {
		//paly music ...
		AssetFileDescriptor fileDescriptor = context.getAssets().openFd(voicePath);
		if(mediaPlayer == null ) {
			mediaPlayer = new MediaPlayer();
		}
		if(mediaPlayer.isPlaying()) {
			mediaPlayer.stop();
		}
		mediaPlayer.reset();
		mediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(),fileDescriptor.getStartOffset(),
				fileDescriptor.getLength());
		mediaPlayer.prepare();
		mediaPlayer.start();
	}
	
	public static ArrayList<String> removeString(List<String> strArr,String str){
		ArrayList<String> newArr= null;
		if(strArr!=null&&str!=null){
			newArr = new ArrayList<String>();
			for (String string : strArr) {
				if(!str.equals(string)){
					newArr.add(string);
				}
			}
		}
		return newArr;
	}
	
	public static void registDialog (final Context context) {
		new AlertDialog.Builder(context)
		 .setTitle(R.string.str_dialog_title) 
		 .setMessage(R.string.str_regist_again)
		 	.setPositiveButton(R.string.dialog_btn, new OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					
					try {
						Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); 
						i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
						context.startActivity(i);
						((Activity)context).finish();
					} catch (Exception e) {
						e.printStackTrace();
					}
					
				}
			})
		 	.show();
	}
}
